<?php
//公共模块
class CommonAction extends Action {
    protected $limit;
    protected $map = array();

    public function _initialize() {
        if(!strpos(__ACTION__, 'Login') !== false) $this->_isAdmin();
    }

    private function _isAdmin() {
        if(!session('admin_name')) $this->redirect('Login/index');
    }


    protected function page($count, $pageSize='') {
        import('ORG.Util.Page');
        $pageSize = empty($pageSize) ? getSetting('admin_page') : $pageSize;
        $page = new Page($count, $pageSize);
        $this->limit = $page->firstRow.','.$page->listRows;
        $this->assign('page', $page->show());
    }

    protected function search($field, $special = array()) {
        import('ORG.Util.Search');
        $search = new Search($field, $special);
        $this->map = $search->execute();
        $this->assign('searchform', $search->createForm());
    }

    // memcached
    protected function useMemcached()
    {
        $memcache = new Memcache();
        $memcache->connect('localhost', 11211);
        return $memcache;
    }
}
